home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / Thread Manager / Compiler Stuff / Interfaces / Think Pascal Interface (exp) / Threads.p (think Pascal vers)
Encoding:
Text File  |  1994-11-17  |  5.6 KB  |  196 lines  |  [TEXT/PJMM]

  1. {}
  2. {    File:        Threads.p}
  3. {}
  4. {    Contains:    External Interface to Thread Manager}
  5. {}
  6. {    Copyright:    © 1991-1994 by Apple Computer, Inc., all rights reserved.}
  7. {}
  8. {}
  9. {}
  10.  
  11. {$IFC UNDEFINED UsingIncludes}
  12. {$SETC UsingIncludes := 0}
  13. {$ENDC}
  14.  
  15. unit Threads;
  16. interface
  17.  
  18.     { UsingThreads }
  19.  
  20. { Thread Gestalt Selectors }
  21.     const
  22.         gestaltThreadMgrAttr = 'thds';                { Thread Manager attributes }
  23.         gestaltThreadMgrPresent = 0;                { bit true if Thread Mgr is present }
  24.         gestaltSpecificMatchSupport = 1;            { bit true if Thread Mgr supports exact match creation option }
  25.         gestaltThreadsLibraryPresent =  2;            { bit true if ThreadsLibrary (Native version) has been loaded }
  26.  
  27.  
  28. { Thread states }
  29.     type
  30.         ThreadState = INTEGER;
  31.  
  32.     const
  33.         kReadyThreadState = 0;
  34.         kStoppedThreadState = 1;
  35.         kRunningThreadState = 2;
  36.  
  37. { Thread environment characteristics }
  38.     type
  39.         ThreadTaskRef = Ptr;
  40.  
  41. { Thread characteristics }
  42.     type
  43.         ThreadStyle = LONGINT;
  44.  
  45.     const
  46.         kCooperativeThread = 1;
  47.         kPreemptiveThread = 2;
  48.  
  49. { Thread identifiers }
  50.     type
  51.         ThreadID = LONGINT;
  52.  
  53.     const
  54.         kNoThreadID = 0;
  55.         kCurrentThreadID = 1;
  56.         kApplicationThreadID = 2;
  57.  
  58. { Options when creating a thread }
  59.     type
  60.         ThreadOptions = LONGINT;
  61.  
  62.     const
  63.         kNewSuspend = 1;
  64.         kUsePremadeThread = 2;
  65.         kCreateIfNeeded = 4;
  66.         kFPUNotNeeded = 8;
  67.         kExactMatchThread = 16;
  68.  
  69. { Information supplied to the custom scheduler }
  70.     type
  71.         SchedulerInfoRecPtr = ^SchedulerInfoRec;
  72.         SchedulerInfoRec = record
  73.                 InfoRecSize: LONGINT;
  74.                 CurrentThreadID: ThreadID;
  75.                 SuggestedThreadID: ThreadID;
  76.                 InterruptedCoopThreadID: ThreadID;
  77.             end;
  78.  
  79. { Routine proc prototypes }
  80.     type
  81.     { Prototype for a thread's entry routine }
  82.         ThreadEntryProcPtr = ProcPtr;            { FUNCTION ThreadMain(threadParam: LONGINT): LONGINT; }
  83.  
  84.     { Prototype for a custom scheduler }
  85.         ThreadSchedulerProcPtr = ProcPtr;        { FUNCTION ThreadScheduler(schedulerInfo: SchedulerInfoRec): ThreadID; }
  86.  
  87.     { Prototype for a custom switcher }
  88.         ThreadSwitchProcPtr = ProcPtr;            { PROCEDURE ThreadSwitcher(threadBeingSwitched: ThreadID; switchProcParam: LONGINT); }
  89.  
  90.     { Prototype for a custom termination notification routine}
  91.         ThreadTerminationProcPtr = ProcPtr;        { PROCEDURE ThreadTerminator(threadTerminated: ThreadID; terminationProcParam: LONGINT); }
  92.  
  93.     { Prototypes for debugger new, dispose & schedule thread notification }
  94.         DebuggerNewThreadProcPtr = ProcPtr;            { PROCEDURE DebuggerNewThread(threadCreated: ThreadID); }
  95.         DebuggerDisposeThreadProcPtr = ProcPtr;        { PROCEDURE DebuggerDisposeThread(threadCreated: ThreadID); }
  96.         DebuggerThreadSchedulerProcPtr = ProcPtr;    { FUNCTION DebuggerThreadScheduler(schedulerInfo: SchedulerInfoRec): ThreadID; }
  97.  
  98.  
  99. { Errors }
  100.     const
  101.         threadTooManyReqsErr = -617;
  102.         threadNotFoundErr = -618;
  103.         threadProtocolErr = -619;
  104.  
  105.  
  106. { Thread Manager routines }
  107.     function CreateThreadPool (threadStylex: ThreadStyle; numToCreate: INTEGER; stackSize: Size): OSErr;
  108.     inline
  109.         $303C, $0501, $ABF2;
  110.  
  111.     function GetFreeThreadCount (threadStylex: ThreadStyle; var freeCount: INTEGER): OSErr;
  112.     inline
  113.         $303C, $0402, $ABF2;
  114.  
  115.     function GetSpecificFreeThreadCount ( threadStylex: ThreadStyle; stackSize: Size; VAR freeCount: INTEGER):OSErr;
  116.     inline
  117.         $303C, $0615, $ABF2;
  118.     
  119.     function GetDefaultThreadStackSize (threadStylex: ThreadStyle; var stackSize: Size): OSErr;
  120.     inline
  121.         $303C, $0413, $ABF2;
  122.  
  123.     function ThreadCurrentStackSpace (thread: ThreadID; var freeStack: LONGINT): OSErr;
  124.     inline
  125.         $303C, $0414, $ABF2;
  126.  
  127.     function NewThread (threadStylex: ThreadStyle; threadEntry: ThreadEntryProcPtr; threadParam: LONGINT; stackSize: Size; options: ThreadOptions; threadResult: LongIntPtr; var threadMade: ThreadID): OSErr;
  128.     inline
  129.         $303C, $0E03, $ABF2;
  130.  
  131.     function DisposeThread (threadToDump: ThreadID; threadResult: LONGINT; recycleThread: BOOLEAN): OSErr;
  132.     inline
  133.         $303C, $0504, $ABF2;
  134.  
  135.     function YieldToThread (suggestedThread: ThreadID): OSErr;
  136.     inline
  137.         $303C, $0205, $ABF2;
  138.  
  139.     function YieldToAnyThread: OSErr;
  140.     inline
  141.         $42A7, $303C, $0205, $ABF2;
  142.  
  143.     function GetCurrentThread (var currentThreadID: ThreadID): OSErr;
  144.     inline
  145.         $303C, $0206, $ABF2;
  146.  
  147.     function GetThreadState (threadToGet: ThreadID; var threadStatex: ThreadState): OSErr;
  148.     inline
  149.         $303C, $0407, $ABF2;
  150.  
  151.     function SetThreadState (threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID): OSErr;
  152.     inline
  153.         $303C, $0508, $ABF2;
  154.  
  155.     function SetThreadStateEndCritical (threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID): OSErr;
  156.     inline
  157.         $303C, $0512, $ABF2;
  158.  
  159.     function SetThreadScheduler (threadScheduler: ThreadSchedulerProcPtr): OSErr;
  160.     inline
  161.         $303C, $0209, $ABF2;
  162.  
  163.     function SetThreadSwitcher (thread: ThreadID; threadSwitcher: ThreadSwitchProcPtr; switchProcParam: LONGINT; inOrOut: BOOLEAN): OSErr;
  164.     inline
  165.         $303C, $070A, $ABF2;
  166.  
  167.     function SetThreadTerminator (thread: ThreadID; threadTerminator: ThreadTerminationProcPtr; terminationProcParam: LONGINT): OSErr;
  168.     inline
  169.         $303C, $0611, $ABF2;
  170.  
  171.     function ThreadBeginCritical: OSErr;
  172.     inline
  173.         $303C, $000B, $ABF2;
  174.  
  175.     function ThreadEndCritical: OSErr;
  176.     inline
  177.         $303C, $000C, $ABF2;
  178.  
  179.     function SetDebuggerNotificationProcs (notifyNewThread: DebuggerNewThreadProcPtr; notifyDisposeThread: DebuggerDisposeThreadProcPtr; notifyThreadScheduler: DebuggerThreadSchedulerProcPtr): OSErr;
  180.     inline
  181.         $303C, $060D, $ABF2;
  182.  
  183.     function GetThreadCurrentTaskRef (var threadTRef: ThreadTaskRef): OSErr;
  184.     inline
  185.         $303C, $020E, $ABF2;
  186.  
  187.     function GetThreadStateGivenTaskRef (threadTRef: ThreadTaskRef; threadToGet: ThreadID; var threadStatex: ThreadState): OSErr;
  188.     inline
  189.         $303C, $060F, $ABF2;
  190.  
  191.     function SetThreadReadyGivenTaskRef (threadTRef: ThreadTaskRef; threadToSet: ThreadID): OSErr;
  192.     inline
  193.         $303C, $0410, $ABF2;
  194.  
  195. implementation
  196. end.